unit Con_TabelaPreco;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Formulario_Padrao_Consulta, StdCtrls, Buttons, ExtCtrls, Grids, DBGrids,
  Db, Dbtables, TFlatButtonUnit, DBClient, Provider;

type
  TFrmCon_TabelaPreco = class(TFrmConsulta)
    Label1: TLabel;
    EdtDescricao: TEdit;
    DbgTabelapreco: TDBGrid;
    btnGravar: TFlatButton;
    dsp: TDataSetProvider;
    CDS: TClientDataSet;
    procedure BtnFecharClick(Sender: TObject);
    procedure EdtDescricaoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormActivate(Sender: TObject);
    procedure btnGravarClick(Sender: TObject);
    procedure DbgTabelaprecoTitleClick(Column: TColumn);
  private
    { Private declarations }
    procedure FazConsulta;
  public
    { Public declarations }
    Tab_codigo: string;
  end;

var
  FrmCon_TabelaPreco: TFrmCon_TabelaPreco;

implementation

uses Dm, Biblio, clsTabelaPreco, Cad_TabelaPreco, menu;

{$R *.DFM}

var
  TabelaPreco: TTabelaPreco;
  tds: Tdatasource;
  tq: Tquery;

procedure TFrmCon_TabelaPreco.BtnFecharClick(Sender: TObject);
begin
  inherited;
  Tab_codigo := CDS.fieldbyname('Tab_codigo').asstring;
  tds.free;
  tq.free;
end;

procedure TFrmCon_TabelaPreco.EdtDescricaoKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if key = 12 then begin
    FazConsulta;
    EdtDescricao.setfocus;
  end;
end;

procedure TFrmCon_TabelaPreco.FormActivate(Sender: TObject);
begin
  inherited;
  if FileExists(caminho_personal + 'belquimica') then begin
    btnGravar.Visible := False;
  end;
  tds := TDataSource.create(FrmCon_TabelaPreco);
  tq := Tquery.create(FrmCon_TabelaPreco);
  tq.databasename := dmint.db.databasename;
  tq.active := False;
  dsp.DataSet := tq;
  tds.DataSet := CDS;
  fazconsulta;
  CDS.Close;
  CDS.Open;
  EdtDescricao.setfocus;
end;

procedure TFrmCon_TabelaPreco.FazConsulta;
begin
  if EdtDescricao.text = '' then
    EdtDescricao.text := ' ';
  TabelaPreco := TTabelaPreco.Create;
  TabelaPreco.Consultar(tq, EdtDescricao.text);
  tq.open;
  dbgTabelaPreco.DataSource := tds;
  dbgTabelaPreco.Refresh;
  CDS.Close;
  CDS.Open;
  TabelaPreco.free;
end;

procedure TFrmCon_TabelaPreco.btnGravarClick(Sender: TObject);
var
  f1: TFrmCad_TabelaPreco;
begin
  inherited;
  f1 := TFrmCad_TabelaPreco.Create(Self);
  f1.btnC_TabelaPreco.Visible := False;
  f1.ShowModal;
  f1.Free;
  FazConsulta;
end;

procedure TFrmCon_TabelaPreco.DbgTabelaprecoTitleClick(Column: TColumn);
begin
  inherited;
  SortClientDataSet(CDS, Column.FieldName);
  //CDS.IndexFieldNames := Column.FieldName;
end;

end.

